package com.borqsprocessmanager.fragments;

import java.util.HashMap;

import android.app.Fragment;
import android.os.Bundle;
import android.widget.ListView;

import com.borqsprocessmanager.BatteryManagerService;
import com.borqsprocessmanager.IService;
import com.borqsprocessmanager.MainActivity;
import com.borqsprocessmanager.adapter.SectionAdapter;
import com.borqsprocessmanager.info.ProcessStatsInfo;
import com.borqsprocessmanager.info.ReceiverProcessInfo;
import com.borqsprocessmanager.util.Log;
import com.borqsprocessmanager.view.SwipeDismissListViewTouchListener;

public class BaseFragment extends Fragment {
    protected BatteryManagerService mBatteryManagerService;
    protected boolean isGetService = false;
    protected MainActivity mActivity;
    protected HashMap<String, ReceiverProcessInfo> mActionMap;
    protected HashMap<String, ProcessStatsInfo> mWhiteMap;
    // protected int mSampleId;
    protected IService mPersonService;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        mActivity = (MainActivity) getActivity();
    }

    public BatteryManagerService getmBatteryManagerService() {
        return mBatteryManagerService;
    }

    public void onBindServiced(IService personService,
            HashMap<String, ReceiverProcessInfo> actionMap,
            HashMap<String, ProcessStatsInfo> whiteMap) {
        mPersonService = personService;
        mActionMap = actionMap;
        mWhiteMap = whiteMap;
        isGetService = true;
    }

    protected void setListViewListener(ListView list,
            final SectionAdapter adapter) {
        SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(
                list,
                new SwipeDismissListViewTouchListener.OnDismissCallback() {
                    @Override
                    public void onDismiss(ListView listView,
                            int[] reverseSortedPositions) {
                        for (int position : reverseSortedPositions) {
                            Log.v("xxx", "listView.getHeaderViewsCount()=="
                                    + listView.getHeaderViewsCount());
                            int resPosition = position
                                    - listView.getHeaderViewsCount();
                            if (resPosition >= 0) {
                                dismisListViewItem(resPosition);
                                adapter.remove(resPosition);
                            }
                        }
                        adapter.notifyDataSetChanged();
                    }
                });
        list.setOnTouchListener(touchListener);
        list.setOnScrollListener(touchListener.makeScrollListener());
    }

    protected void dismisListViewItem(int position) {

    }
}
